//
// Created by xili on 2024/8/27 20:32.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int longestSubarray(vector<int> &nums) {
        int ans = 0, left = 0, countZero = 0;
        int n = nums.size();
        for (int right = 0; right < n; right++) {
            if (nums[right] == 0) {
                countZero++;
            }
            while (countZero > 1) {
                if (nums[left] == 0) {
                    countZero--;
                }
                left++;
            }
            ans = max(ans, right - left);
        }
        return ans;
    }
};
